import api from '../axios/axios';
import type {
  ProblemListRequest,
  ProblemListResponse
} from '../dto/problemManagement';

// 题目列表相关API
export const problemListApi = {
  // 获取题目列表（分页）
  getProblemList: (params: ProblemListRequest): Promise<ProblemListResponse> => {
    return api.post('/user/problem/list', params);
  },

  // 获取题目列表（带默认参数）
  getProblemListWithDefaults: (params?: Partial<ProblemListRequest>): Promise<ProblemListResponse> => {
    const defaultParams: ProblemListRequest = {
      page: 1,
      size: 10,
      isAsc: true,
      tagId: [],
      ...params
    };
    return api.post('/user/problem/list', defaultParams);
  },

  // 搜索题目
  searchProblems: (keyword: string, page: number = 1, size: number = 10): Promise<ProblemListResponse> => {
    return api.post('/user/problem/list', {
      keyword,
      page,
      size,
      isAsc: true
    });
  },

  // 按难度筛选题目
  getProblemsByDifficulty: (difficulty: number, page: number = 1, size: number = 10): Promise<ProblemListResponse> => {
    return api.post('/user/problem/list', {
      difficulty,
      page,
      size,
      isAsc: true
    });
  },

  // 按标签筛选题目
  getProblemsByTags: (tagIds: number[], page: number = 1, size: number = 10): Promise<ProblemListResponse> => {
    return api.post('/user/problem/list', {
      tagId: tagIds,
      page,
      size,
      isAsc: true
    });
  },

  // 按状态筛选题目
  getProblemsByStatus: (status: number, page: number = 1, size: number = 10): Promise<ProblemListResponse> => {
    return api.post('/user/problem/list', {
      status,
      page,
      size,
      isAsc: true
    });
  }
};

export default problemListApi; 